const Omit = require("../template")

function testOmitBasic() {
  console.log(
    "1. 基本排除功能测试:",
    (() => {
      const object = { a: 1, b: 2, c: 3, d: 4, e: 5 }
      const result = Omit.omit(object, 'a', 'c')
      const expected = { b: 2, d: 4, e: 5 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "2. 数组路径排除测试:",
    (() => {
      const object = { a: 1, b: 2, c: 3, d: 4, e: 5 }
      const result = Omit.omit(object, ['a', 'c'])
      const expected = { b: 2, d: 4, e: 5 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "3. 深度排除测试:",
    (() => {
      const object = { a: { b: { c: 1 } }, d: { e: { f: 2 } }, g: 3 }
      const result = Omit.omitDeep(object, 'a.b.c', 'd.e.f')
      const expected = { g: 3 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "4. 条件排除测试:",
    (() => {
      const object = { a: 1, b: 2, c: 3, d: 4, e: 5 }
      const result = Omit.omitBy(object, (value, key) => value > 3)
      const expected = { a: 1, b: 2, c: 3 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "5. 类型排除测试:",
    (() => {
      const object = { a: 1, b: '2', c: 3, d: '4', e: 5 }
      const result = Omit.omitByType(object, 'string')
      const expected = { a: 1, c: 3, e: 5 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "6. 正则排除测试:",
    (() => {
      const object = { a1: 1, b2: 2, c3: 3, d4: 4, e5: 5 }
      const result = Omit.omitByPattern(object, /[0-9]/)
      return Object.keys(result).length === 0
    })()
  )

  console.log(
    "7. 默认值排除测试:",
    (() => {
      const object = { a: 1, b: 2, c: 3, d: 4, e: 5 }
      const result = Omit.omitWithDefaults(object, 'a', 'c', { b: 0, d: 0 })
      const expected = { b: 0, d: 0, e: 5 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "8. 转换排除测试:",
    (() => {
      const object = { a: 1, b: 2, c: 3, d: 4, e: 5 }
      const result = Omit.omitWithTransform(object, 'a', 'c', { b: x => x * 2, d: x => x * 3 })
      const expected = { b: 4, d: 12, e: 5 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "9. 验证排除测试:",
    (() => {
      const object = { a: 1, b: 2, c: 3, d: 4, e: 5 }
      const result = Omit.omitWithValidation(object, 'a', 'c', { min: 1, max: 10 })
      const expected = { b: 2, d: 4, e: 5 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "10. 空对象排除测试:",
    (() => {
      const object = {}
      const result = Omit.omit(object, 'a', 'b')
      return Object.keys(result).length === 0
    })()
  )

  console.log(
    "11. 单属性对象排除测试:",
    (() => {
      const object = { a: 1 }
      const result = Omit.omit(object, 'a')
      return Object.keys(result).length === 0
    })()
  )

  console.log(
    "12. this上下文排除测试:",
    (() => {
      const omitObj = {
        multiplier: 2,
        processOmit: function(object) {
          const result = Omit.omit(object, 'a', 'c')
          return Object.keys(result).length * this.multiplier
        }
      }
      const object = { a: 1, b: 2, c: 3, d: 4 }
      return omitObj.processOmit(object) === 4 // 2*2=4
    })()
  )

  console.log(
    "13. 复杂对象this绑定排除测试:",
    (() => {
      const omitConfigObj = {
        config: { threshold: 2 },
        processWithConfig: function(object) {
          const result = Omit.omit(object, 'a', 'c')
          return Object.keys(result).length >= this.config.threshold
        }
      }
      const object = { a: 1, b: 2, c: 3, d: 4 }
      return omitConfigObj.processWithConfig(object) === true
    })()
  )
}

testOmitBasic()
